/**
 * Created by Jehuty on 16/11/30.
 */
$(function () {
    commit_load();

    if($(window).width()>768){
        $(".navbar-fixed-top").autoHidingNavbar({});
        $(".navbar-fixed-top").css("backgroundColor","rgba(0,0,0,0.4)");
    };
})


function commit_load() {
    //第一次加载
    var index = 1,pagesize=4;
    ajax(index,pagesize);
    btn_effct()

    function btn_effct() {

        $(".my_btn a").on("click",function () {
            $(this).siblings("a").removeClass("focus").end()
                .addClass("focus")
        });

        //获取总页数
        var maxIndex;
        $.getJSON(myUrl.url1,{pagesize:pagesize},function (data) {
            maxIndex = data.pagecount;
        });

        //newer
        $("#newer_btn").on("click",function () {
            index--;
            //如果已经是第一页了，则弹出框并固定index
            if(index<1){
                index=1;
                layerOut("已经是第一页啦")
            };
            ajax(index,pagesize);
        });

        //older
        $("#older_btn").on("click",function () {
            index++;
            //如果是最后一页了，弹出框并固定index
            if(index>maxIndex){
                index=maxIndex;
                layerOut("已经到最后页啦")
            }
            ajax(index,pagesize)
        })
    }


    function layerOut(text){
        layer.open({
            title:false,
            type: 1,
            time:1000,
            area: ['200px', '100px'],
            shadeClose: true,
            content: '\<\div style="text-align:center;font-size:20px;height:100px;width:200px;line-height:100px;background-color:rgba(0,0,0,0.6);color:white;">'+text+'\<\/div>'
        });
    }


    function ajax(pageindex,pagesize) {
        $.ajax({
            url:myUrl.url2,
            data:{pageindex:pageindex,pagesize:pagesize},
            type:"get",
            success:function (data) {
                    data = {
                        list :data
                    }
                    var html = template("template_commit",data);
                    $("#commit_cotainer").html(html)

            }
        })
    }

}








